package com.e.dianshang.controller;

import com.e.dianshang.service.MyeyeService;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: HP
 * Date: 2020/11/14 14:27
 * Description:
 */
@RestController
@CrossOrigin
@Api(value = "用户关注的控制器",tags = "用户关注api")
public class MyeyeController {

    @Resource
    MyeyeService myeyeService;

    JsonResult jsonResult;

    // 添加商品关注
    @RequestMapping("insertMyeye")
    @ApiOperation(value = "用户添加收藏记录",httpMethod = "POST")
    @ApiImplicitParam(name = "map",value = "收藏表的相关字段")
    public Map insertMyEye(@RequestBody Map map){
        jsonResult=new JsonResult();
        Integer integer = myeyeService.insertMyEye(map);
        if (integer>0){
            jsonResult.setCode("1");
            jsonResult.setMsg("关注成功");
        }else {
            jsonResult.setCode("0");
        }

        return jsonResult.getValues();
    }

    // 取消商品关注
    @RequestMapping("deleteMyeye")
    @ApiOperation(value = "用户删除收藏记录",httpMethod = "GET")
    @ApiImplicitParam(name = "openid",value = "用户电话或者用户id",dataType = "string")
    public Map deleteMyeye(@RequestBody Map map){
        jsonResult=new JsonResult();
        Integer integer = myeyeService.deleteMyeye(map);
        if (integer>0){
            jsonResult.setCode("1");
            jsonResult.setMsg("取消关注成功");
        }else {
            jsonResult.setCode("0");
        }
        return jsonResult.getValues();
    }
}
